package com.sparrow.rpc.domain;

import com.google.common.base.Objects;

/**
 * 节点类，包含节点的 ID、IP 和端口信息
 */
public class RpcNode {
    private String id;
    private String ip;
    private int port;

    public RpcNode(String id, String ip, int port) {
        this.id = id;
        this.ip = ip;
        this.port = port;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        RpcNode node = (RpcNode) o;
        return id .equals(node.id)  && port == node.port && Objects.equal(ip, node.ip);
    }

    @Override
    public int hashCode() {
        return Objects.hashCode(id, ip, port);
    }

    public String getId() {
        return id;
    }

    public String getIp() {
        return ip;
    }

    public int getPort() {
        return port;
    }

    @Override
    public String toString() {
        return "Node{id=" + id + ", ip='" + ip + "', port=" + port + "}";
    }
}
